//
//  ZYMainTabBarViewController.swift
//  weibo-Swift
//
//  Created by Apple on 16/7/19.
//  Copyright © 2016年 Apple. All rights reserved.
//

import UIKit

class ZYMainTabBarViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
//        设置自定义的tabbar
        let mainTabBar = ZYMainTbaBar()
        
        mainTabBar.composeCallback = {
             print("控制器里面知道点击了加号按钮")
//        TODO
        }
        
//        设置maintabbar的tabbar
//        这个属性不能直接复制。因为tabbar的get 是only-只读 就不能直接赋值
//        self.tabBar = mainTabBar
//        这里使用KVC 简介赋值
        self.setValue(mainTabBar, forKey: "tabBar")
        
        
        
        
        addChildviewController()
    }
//    添加子控件
    func addChildviewController(){
        
        
        let homeVC = ZYHomeTableViewController()
        setRootController(homeVC, title: "首页", image:"tabbar_home")
        
        let messageVC = ZYMessageTableViewController()
        setRootController(messageVC, title: "消息", image: "tabbar_message_center")
        
        let discoveryVC = ZYDiscoveryTableViewController()
        setRootController(discoveryVC, title: "发现", image: "tabbar_discover")
        
        let profileVC = ZYProfileTableViewController()
        setRootController(profileVC, title: "我", image: "tabbar_profile")
    
    }
//设置子控件的图片和文字
    func setRootController(controller: UITableViewController , title: String , image: String){
   
        controller.title = title
        controller.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName : UIColor.orangeColor()], forState: UIControlState.Selected)
        controller.tabBarItem.image = UIImage(named: image)
        
        let selectedImageName = image + "_selected"
        controller.tabBarItem.selectedImage = UIImage(named: selectedImageName)?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        
        self.addChildViewController(UINavigationController(rootViewController: controller))
    
    
    }

   
    
    
    
}
